<!--
~ Copyright 2018-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<div id="ov-intent" xmlns="http://www.w3.org/1999/html">
    <onos-loading [theme]="'light'" [running]="loadingIconShown"></onos-loading>
    <div class="tabular-header">
        <onos-flash id="intentActionFlash" message="{{ intentActionMsg }}"></onos-flash>
        <onos-confirm message="{{ warnMsg }}" (chosen)="dOk($event)"></onos-confirm>
        <h2>
            Intents ({{tableData.length}} total)
        </h2>
        <div class="ctrl-btns">
            <div class="refresh" (click)="toggleRefresh()">
                <!-- See icon.theme.css for the defintions of the classes active and refresh-->
                <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="42" toolTip="{{ autoRefreshTip }}"></onos-icon>
            </div>
            <div class="separator"></div>
            <span *ngIf="brief" (click)="briefToggle()">
                <div>
                    <onos-icon classes="{{'active-rect'}}" iconId="plus" iconSize="42" toolTip="{{detailTip}}">
                    </onos-icon>
                </div>
            </span>
            <span *ngIf="!brief" (click)="briefToggle()">
                <div>
                    <onos-icon classes="{{'active-rect'}}" iconId="minus" iconSize="42" toolTip="{{briefTip}}">
                    </onos-icon>
                </div>
            </span>
            <div class="separator"></div>
            <div routerLink="/topo2" [queryParams]="{ intentId: selId, appId: intentData.appId, appName: intentData.appName, intentType: intentData.type }" routerLinkActive="active">
                <onos-icon classes="{{!!selId ? 'active-rect' :undefined}}" iconId="topo" iconSize="42" toolTip="{{ topoTip }}"></onos-icon>
            </div>
            <div (click)="!!selId && intentState() === 'Withdrawn' ? confirmAction(IntentActionEnum.RESUBMIT):''">
                <onos-icon classes="{{!!selId && intentState()  === 'Withdrawn' ? 'active-rect' :undefined}}" iconId="play" iconSize="42"
                    toolTip="{{ resubmitTip }}"></onos-icon>
            </div>
            <div (click)="!!selId && intentState() === 'Installed' ? confirmAction(IntentActionEnum.WITHDRAWN):''">
                <onos-icon classes="{{!!selId && intentState() === 'Installed' ? 'active-rect' :undefined}}" iconId="stop" iconSize="42"
                    toolTip="{{ deactivateTip }}"></onos-icon>
            </div>
            <div (click)="!!selId && intentState() === 'Withdrawn' ? confirmAction(IntentActionEnum.PURGE):''">
                <onos-icon classes="{{!!selId && intentState()  === 'Withdrawn' ? 'active-rect' :undefined}}" iconId="garbage" iconSize="42"
                    toolTip="{{ purgeTip }}"></onos-icon>
            </div>
            <div (click)="isHavingWithdrawn() ? confirmAction(IntentActionEnum.PURGEWITHDRAWN):''">
                <onos-icon classes="{{isHavingWithdrawn() ? 'active-rect' :undefined}}" iconId="garbage" iconSize="47" toolTip="{{ purgeAllTip }}"></onos-icon>
            </div>
        </div>
    </div>

    <div class="summary-list">
        <div class="table-header">
            <table onosTableResize>
                <tr>
                    <td colId="appId" (click)="onSort('appId')">Application ID
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('appId')"></onos-icon>
                    </td>
                    <td colId="key" (click)="onSort('key')">Key
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('key')"></onos-icon>
                    </td>
                    <td colId="type" (click)="onSort('type')">Type
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('type')"></onos-icon>
                    </td>
                    <td colId="priority" (click)="onSort('priority')">Priority
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('priority')"></onos-icon>
                    </td>
                    <td colId="state" (click)="onSort('state')">State
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('state')"></onos-icon>
                    </td>
                </tr>
            </table>
        </div>
        <div class="table-body">
            <table onosTableResize id-prop="key">
                <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
                    <td colspan="5">{{ annots.noRowsMsg }}</td>
                </tr>
                <ng-template ngFor let-intent [ngForOf]="tableData">
                    <tr (click)="selectCallback($event, intent)" [ngClass]="{selected: intent.key === selId, 'data-change': isChanged(intent.key)}">
                        <td>{{intent.appId}}</td>
                        <td>{{intent.key}}</td>
                        <td>{{intent.type}}</td>
                        <td>{{intent.priority}}</td>
                        <td>{{intent.state}}</td>
                    </tr>
                    <tr (click)="selectCallback($event, intent)" [hidden]="brief" [ngClass]="{selected: intent.key === selId, 'data-change': isChanged(intent.key)}">
                        <td class="resources" colspan="5">{{ intent.resources }}</td>
                    </tr>
                    <tr (click)="selectCallback($event, intent)" [hidden]="brief" [ngClass]="{selected: intent.key === selId, 'data-change': isChanged(intent.key)}">
                        <td class="details" colspan="5">{{ intent.details }}</td>
                    </tr>
                </ng-template>
            </table>
        </div>
    </div>
</div>
